import java.util.Scanner;

/**
 * 特别数的和
 */
public class SumSpecialNumbers {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            if (check(i)) {
                sum += i;
            }
        }
        System.out.println(sum);
        sc.close();
    }

    private static boolean check(int i) {
        while (i > 0) {
            int t = i % 10;
            if (t == 2 || t == 0 || t == 1 || t == 9) {
                return true;
            }
            i /= 10;
        }
        return false;
    }
}
